package com.superiron.scaffold.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @author ：yzg
 * @date ：Created in 2022/9/6 11:09
 * @description：
 * @modified By：
 * @version: $
 */
@Configuration
@EnableTransactionManagement
@MapperScan("com.superiron.scaffold.dao")
public class MyBatisConfig {
	@Bean
	public MybatisPlusInterceptor mybatisPlusInterceptor() {
		MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
		// 配置乐观锁插件
		mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
		// 配置分页插件
		mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
		return mybatisPlusInterceptor;
	}
	
	/**
	 * 自定义内置选装件
	 * @return
	 */
	@Bean
	public MySqlInjector sqlInjector() {
		return new MySqlInjector();
	}
}
